package com.example.androidproject.movie.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.androidproject.R;
import com.example.androidproject.movie.bean.ResultBeanData;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import jp.wasabeef.glide.transformations.BlurTransformation;

public class MovieDetailActivity extends Activity implements View.OnClickListener {
    private final String TAG = "GGSTUDY";
    private TextView tv_movie_title;
    private ImageView iv_movie_detail;
    private ImageView iv_movie_detail_bc;
    private TextView movie_title, movie_director, movie_type, movie_star, movie_introduction;
    private Button paly_btn;
    private ResultBeanData.DataBean data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_movie_detail);
        //设置顶部状态栏为透明
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        getWindow().setStatusBarColor(Color.TRANSPARENT);
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
        intView();
        initPage();

    }

    // 去掉空格 换行那些
    private String replaceBlank(String classify) {
        String CLASSIFY = "";
        if (classify != null) {
            Pattern pattern = Pattern.compile("\\s*|\t|\r|\n");
            Matcher matcher = pattern.matcher(classify);
            CLASSIFY = matcher.replaceAll("");
        }
        return CLASSIFY;
    }

    private void intView() {
        tv_movie_title = findViewById(R.id.tv_movie_title);
        iv_movie_detail = findViewById(R.id.iv_movie_detail);
        iv_movie_detail_bc = findViewById(R.id.iv_movie_detail_bc);
        movie_title = findViewById(R.id.movie_title);
        movie_director = findViewById(R.id.movie_director);
        movie_type = findViewById(R.id.movie_type);
        movie_star = findViewById(R.id.movie_star);
        movie_introduction = findViewById(R.id.tv_movie_introduction);
        paly_btn = findViewById(R.id.movie_playBtn);
    }

    private void initPage() {
        Intent intent = getIntent();
        // 拆Bundle
        data = (ResultBeanData.DataBean) intent.getParcelableExtra("data");
        tv_movie_title.setText(data.getName());
        // 设置模糊
//        MultiTransformation mation4 = new MultiTransformation(new BlurTransformation(30));
        Glide.with(this).load(data.getSrc())
//                .apply(RequestOptions.bitmapTransform(mation4))
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
                .into(iv_movie_detail_bc);

        Glide.with(this).load(data.getSrc())
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
                .into(iv_movie_detail);
        String classify = replaceBlank(data.getClassify());
        movie_title.setText(data.getName());
        movie_director.setText("导演：  " + data.getDirector());
        movie_type.setText("类型：  " + classify);
        movie_star.setText("主演:  " + data.getStar());
        movie_introduction.setText(data.getInfo());
        paly_btn.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.movie_playBtn:
                Intent intent = new Intent(this, MoviePlayActivity.class);
                Bundle bundle = new Bundle();
                bundle.putParcelable("data", data);
                intent.putExtras(bundle);
                startActivity(intent);
                break;
        }
    }
}